package com.nand.module.function.ui;

import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.lzy.okgo.model.HttpParams;
import com.nand.library.base.base.BaseActivity;
import com.nand.library.base.bean.ResponseBean;
import com.nand.library.base.http.Callback;
import com.nand.library.base.http.MyCallback;
import com.nand.library.base.http.OkGoBuilder;
import com.nand.library.base.http.OkGoUtils;
import com.nand.module.function.R;
import com.nand.module.function.bean.EqDatailBean;
import com.nand.module.function.constant.URL;
import com.nand.module.function.utils.LogUtils;
import com.nand.module.function.view.ImageActivity;

import java.util.ArrayList;

public class EqLedgerDetalisActivity extends BaseActivity {

    private TextView mTvSbbm;
    private TextView mTvSbmc;
    private TextView mTvSbxh;
    private TextView mTvSbgg;
    private TextView mTvGc;
    private TextView mTvCj;
    private TextView mTvCx;
    private TextView mTvGys;
    private TextView mTvGysdh;
    private TextView mTvBgbm;
    private TextView mTvSybm;
    private TextView mTvSbgs, mTvCf;
    private int id;
    private ImageView mIvZpck;
    ArrayList<String> strings = new ArrayList<>();
    private String filePath;

    @Override
    protected int initLayout() {
        return R.layout.activity_eq_ledger_detalis;
    }

    @Override
    protected void initView() {
        id = getIntent().getIntExtra("id", 1);
        mTvSbbm = findViewById(R.id.tv_sbbm);
        mTvSbmc = findViewById(R.id.tv_sbmc);
        mTvSbxh = findViewById(R.id.tv_sbxh);
        mTvSbgg = findViewById(R.id.tv_sbgg);
        mTvGc = findViewById(R.id.tv_gc);
        mTvCj = findViewById(R.id.tv_cj);
        mTvCx = findViewById(R.id.tv_cx);
        mTvGys = findViewById(R.id.tv_gys);
        mTvGysdh = findViewById(R.id.tv_gysdh);
        mTvBgbm = findViewById(R.id.tv_bgbm);
        mTvSybm = findViewById(R.id.tv_sybm);
        mTvSbgs = findViewById(R.id.tv_sbgs);
        mTvCf = findViewById(R.id.tv_cf);
        mIvZpck = findViewById(R.id.iv_zpck);

        mIvZpck.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent1 = new Intent(mContext, ImageActivity.class);
                //intent1.putExtra(ImageActivity.CURRENT_IMG_URL, imgList.get(0));
                intent1.putStringArrayListExtra(ImageActivity.IMG_LIST, strings);
                startActivity(intent1);

            }
        });
    }

    protected boolean isActionBar() {
        return true;
    }

    @Override
    protected void initData() {
            mActionBar().setCenterText("设备台账详情");
        HttpParams params = new HttpParams();
        params.put("id", id);
        OkGoUtils.getInstance().post(this, URL.EQ_DETAIL_LIST, params, 1, true, new MyCallback() {
            @Override
            public void onSuccess(ResponseBean response, int id) {
                if (response.getCode() == 200) {
                    String data = response.getDataInfo().toString();
                    LogUtils.e("data========="+data);
                    EqDatailBean listBeans = JSON.parseObject(data, EqDatailBean.class);


                    if (listBeans.getDataList().size() > 0){
                        EqDatailBean.DataListBean bean = listBeans.getDataList().get(0);

                        mTvSbbm.setText(bean.getEquipID());
                        mTvSbmc.setText(bean.getEquipName());
                        mTvSbxh.setText(bean.getEquipModel());
                        mTvSbgg.setText(bean.getEquipType());
                        mTvGc.setText(bean.getFactoryID());
                        mTvCj.setText(bean.getWorkID());
                        mTvCx.setText(bean.getLineID());
                        mTvGys.setText(bean.getSupplierID());
                        mTvGysdh.setText(bean.getSupplierTel());
                        mTvBgbm.setText(bean.getKeepDepartID());
                        mTvSybm.setText(bean.getUseDepartID());
                        mTvSbgs.setText(bean.getEquipBelong());
                        mTvCf.setText(bean.getBuildingName());

                        filePath = bean.getFilePath();
                        if ("".equals(filePath) || null == filePath){
                            mIvZpck.setVisibility(View.GONE);
                            findViewById(R.id.tv_zpck).setVisibility(View.VISIBLE);
                        }else {
                            RequestOptions error = new RequestOptions().placeholder(R.mipmap.image_error).error(R.mipmap.image_error);
                            Glide.with(mContext).asBitmap().load(filePath).apply(error).into(mIvZpck);
                            strings.add(filePath);
                        }

                    }

                } else {
                    showToast(response.getMsg());
                }
            }

            @Override
            public void onError(Throwable e, int id) {

            }
        });
    }
}
